home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
networking
/
ip
/
ka9q
/
src.arc
/
CONFIG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-08-19
|
11KB
|
480 lines
/* Stuff heavily dependent on the configuration info in config.h */
#include <stdio.h>
#include "global.h"
#include "mbuf.h"
#include "proc.h"
#include "cmdparse.h"
#include "config.h"
#include "daemon.h"
#include "timer.h"
#include "iface.h"
#include "usock.h"
#include "kiss.h"
#include "enet.h"
#include "ax25.h"
#include "netrom.h"
#include "ip.h"
#include "tcp.h"
#include "udp.h"
#include "commands.h"
static void showtrace __ARGS((struct iface *ifp));
static int dosock __ARGS((int argc,char *argv[],void *p));
static int dostart __ARGS((int argc,char *argv[],void *p));
static int dostop __ARGS((int argc,char *argv[],void *p));
static int dotrace __ARGS((int argc,char *argv[],void *p));
unsigned Nsessions = NSESSIONS;
int32 Heapsize = HEAPSIZE * (long)1024;
/* daemons to be run at startup time */
struct daemon Daemons[] = {
"killer", 200, killer,
"timer", 512, timerproc,
"network", 1024, network,
"keyboard", 250, keyboard,
NULLCHAR, 0, NULLVFP
};
/* Command lookup and branch tables */
struct cmds Cmds[] = {
/* The "go" command must be first */
"", go, 0, 0, NULLCHAR,
"!", doshell, 0, 0, NULLCHAR,
"abort", doabort, 0, 0, NULLCHAR,
#if (defined(MAC) && defined(APPLETALK))
"applestat", doatstat, 0, 0, NULLCHAR,
#endif
#if (defined(AX25) || defined(ETHER) || defined(APPLETALK))
"arp", doarp, 0, 0, NULLCHAR,
#endif
#ifdef ASY
"asystat", doasystat, 0, 0, NULLCHAR,
#endif
#ifdef AX25
"ax25", doax25, 0, 0, NULLCHAR,
#endif
"attach", doattach, 0, 2,
"attach <hardware> <hw specific options>",
/* This one is out of alpabetical order to allow abbreviation to "c" */
#ifdef AX25
"connect", doconnect, 1024, 3,"connect <interface> <callsign>",
#endif
#ifndef UNIX /* BSD or SYS5 */
"cd", docd, 0, 0, NULLCHAR,
#endif
"close", doclose, 0, 0, NULLCHAR,
"disconnect", doclose, 0, 0, NULLCHAR,
"dir", dodir, 0, 0, NULLCHAR, /* note sequence */
"delete", dodelete, 0, 2, "delete <file>",
"domain", dodomain, 0, 0, NULLCHAR,
#ifdef HS
"hs", dohs, 0, 0, NULLCHAR,
#endif
#ifdef EAGLE
"eaglestat", doegstat, 0, 0, NULLCHAR,
#endif
"echo", doecho, 0, 0, NULLCHAR,
"eol", doeol, 0, 0, NULLCHAR,
#ifndef MSDOS
"escape", doescape, 0, 0, NULLCHAR,
#endif
#ifdef PC_EC
"etherstat", doetherstat, 0, 0, NULLCHAR,
#endif
"exit", doexit, 0, 0, NULLCHAR,
"finger", dofinger, 1024, 0, NULLCHAR,
"forward", doforward, 0, 0, NULLCHAR,
"ftp", doftp, 2048, 2, "ftp <address>",
#ifdef HAPN
"hapnstat", dohapnstat, 0, 0, NULLCHAR,
#endif
"help", dohelp, 0, 0, NULLCHAR,
"hostname", dohostname, 0, 0, NULLCHAR,
"icmp", doicmp, 0, 0, NULLCHAR,
"ip", doip, 0, 0, NULLCHAR,
"kick", dokick, 0, 0, NULLCHAR,
"log", dolog, 0, 0, NULLCHAR,
#ifdef AX25
"mbox", dombox, 0, 0, NULLCHAR,
#endif
"memstat", memstat, 0, 0, NULLCHAR,
#ifdef AX25
"mode", domode, 0, 2, "mode <interface>",
#endif
#ifdef NETROM
"netrom", donetrom, 0, 0, NULLCHAR,
#ifdef NRS
"nrstat", donrstat, 0, 0, NULLCHAR,
#endif /* NRS */
#endif /* NETROM */
"param", doparam, 0, 2, "param <interface>",
"ping", doping, 512, 2, "ping <host> [<length> <interval>]",
"ps", ps, 0, 0, NULLCHAR,
#ifndef UNIX /* BSD or SYS5 */
"pwd", docd, 0, 0, NULLCHAR,
#endif
"record", dorecord, 0, 0, NULLCHAR,
"remote", doremote, 0, 3, "remote [-p port] [-k key] [-a kickaddr] <address> exit|reset|kick",
"rename", dorename, 0, 3, "rename <oldfile> <newfile>",
"reset", doreset, 0, 0, NULLCHAR,
"route", doroute, 0, 0, NULLCHAR,
"session", dosession, 0, 0, NULLCHAR,
"shell", doshell, 0, 0, NULLCHAR,
"smtp", dosmtp, 0, 0, NULLCHAR,
"socket", dosock, 0, 0, NULLCHAR,
#ifdef SERVERS
"start", dostart, 0, 2, "start <servername>", /**/
"stop", dostop, 0, 2, "stop <servername>",
#endif
"tcp", dotcp, 0, 0, NULLCHAR,
"telnet", dotelnet, 1024, 2, "telnet <address>",
#ifdef TRACE
"trace", dotrace, 0, 0, NULLCHAR,
#endif
"udp", doudp, 0, 0, NULLCHAR,
"upload", doupload, 0, 0, NULLCHAR,
"?", dohelp, 0, 0, NULLCHAR,
NULLCHAR, NULLFP, 0, 0,
"Unknown command; type \"?\" for list",
};
/* List of supported hardware devices */
struct cmds Attab[] = {
#ifdef PC_EC
/* 3-Com Ethernet interface */
"3c500", ec_attach, 0, 7,
"attach 3c500 <address> <vector> arpa <label> <buffers> <mtu>",
#endif
#ifdef ASY
/* Ordinary PC asynchronous adaptor */
"asy", asy_attach, 0, 8,
"attach asy <address> <vector> slip|ax25|nrs <label> <buffers> <mtu> <speed>",
#endif
#ifdef PC100
/* PACCOMM PC-100 8530 HDLC adaptor */
"pc100", pc_attach, 0, 8,
"attach pc100 <address> <vector> ax25 <label> <buffers> <mtu> <speed>",
#endif
#ifdef EAGLE
/* EAGLE RS-232C 8530 HDLC adaptor */
"eagle", eg_attach, 0, 8,
"attach eagle <address> <vector> ax25 <label> <buffers> <mtu> <speed>",
#endif
#ifdef HAPN
/* Hamilton Area Packet Radio (HAPN) 8273 HDLC adaptor */
"hapn", hapn_attach, 0, 8,
"attach hapn <address> <vector> ax25 <label> <rx bufsize> <mtu> csma|full",
#endif
#ifdef APPLETALK
/* Macintosh AppleTalk */
"0", at_attach, 0, 7,
"attach 0 <protocol type> <device> arpa <label> <rx bufsize> <mtu>",
#endif
#ifdef NETROM
/* fake netrom interface */
"netrom", nr_attach, 0, 1,
"attach netrom",
#endif
#ifdef PACKET
/* FTP Software's packet driver spec */
"packet", pk_attach, 0, 4,
"attach packet <int#> <label> <buffers> <mtu>",
#endif
#ifdef HS
/* Special high speed driver for DRSI PCPA or Eagle cards */
"hs", hs_attach, 0, 7,
"attach hs <address> <vector> ax25 <label> <buffers> <mtu> <txdelay> <persistence>",
#endif
NULLCHAR,
};
/* Packet tracing stuff */
#ifdef TRACE
#include "trace.h"
/* Dummy structure for loopback tracing */
struct iface Loopback = { NULLIF, "loopback" };
/* Protocol tracing function pointers */
struct trace Tracef[] = {
#ifdef AX25
ax_forus, ax25_dump,
#else
NULLFP, NULLVFP,
#endif /* AX25 */
#ifdef ETHER
ether_forus, ether_dump,
#else
NULLFP, NULLVFP,
#endif /* ETHER */
NULLFP, ip_dump,
#ifdef APPLETALK
at_forus, at_dump,
#else
NULLFP, NULLVFP,
#endif /* APPLETALK */
#ifdef KISS
ki_forus, ki_dump,
#else
NULLFP, NULLVFP,
#endif /* KISS */
};
static int
dotrace(argc,argv,p)
int argc;
char *argv[];
void *p;
{
struct iface *ifp;
if(argc < 2){
showtrace(&Loopback);
for(ifp = Ifaces; ifp != NULLIF; ifp = ifp->next)
showtrace(ifp);
return 0;
}
if(strcmp("loopback",argv[1]) == 0)
ifp = &Loopback;
else
for(ifp = Ifaces; ifp != NULLIF; ifp = ifp->next)
if(strcmp(ifp->name,argv[1]) == 0)
break;
if(ifp == NULLIF){
printf("Interface %s unknown\n",argv[1]);
return 1;
}
if(argc >= 3)
ifp->trace = htoi(argv[2]);
showtrace(ifp);
return 0;
}
/* Display the trace flags for a particular interface */
static void
showtrace(ifp)
register struct iface *ifp;
{
if(ifp == NULLIF)
return;
printf("%s:",ifp->name);
if(ifp->trace & (IF_TRACE_IN | IF_TRACE_OUT)){
if(ifp->trace & IF_TRACE_IN)
printf(" input");
if(ifp->trace & IF_TRACE_OUT)
printf(" output");
if(ifp->trace & IF_TRACE_NOBC)
printf(" - no broadcasts");
if(ifp->trace & IF_TRACE_HEX)
printf(" (Hex/ASCII dump)");
else if(ifp->trace & IF_TRACE_ASCII)
printf(" (ASCII dump)");
else
printf(" (headers only)");
printf("\n");
} else
printf(" tracing off\n");
}
#else /* TRACE */
/* Stubs for tracing disabled */
struct trace Tracef[] = {
NULLFP /* No tracing at all */
};
dump(iface,direction,type,bp)
struct iface *iface;
int direction;
unsigned type;
struct mbuf *bp;
{
}
#endif /* TRACE */
#if defined(AX25) && !defined(NETROM)
/* Stubs for when ax25 is configured wihtout net/rom */
void
nr_route(bp,iaxp)
struct mbuf *bp;
struct ax25_cb *iaxp;
{
free_p(bp);
}
void
nr_nodercv(iface,source,bp)
struct iface *iface;
struct ax25_addr *source;
struct mbuf *bp;
{
free_p(bp);
}
#endif /* defined(AX25) && !defined(NETROM) */
#ifdef SERVERS
/* "start" and "stop" subcommands */
static struct cmds Startcmds[] = {
#ifdef AX25
"ax25", ax25start, 256, 0, NULLCHAR,
#endif
"discard", dis1, 256, 0, NULLCHAR,
"echo", echo1, 256, 0, NULLCHAR,
"finger", finstart, 256, 0, NULLCHAR,
"ftp", ftpstart, 256, 0, NULLCHAR,
#ifdef NETROM
"netrom", nr4start, 256, 0, NULLCHAR,
#endif
"smtp", smtp1, 256, 0, NULLCHAR,
"telnet", tnstart, 256, 0, NULLCHAR,
"remote", rem1, 256, 0, NULLCHAR,
NULLCHAR,
};
static struct cmds Stopcmds[] = {
#ifdef AX25
"ax25", ax250, 0, 0, NULLCHAR,
#endif
"discard", dis0, 0, 0, NULLCHAR,
"echo", echo0, 0, 0, NULLCHAR,
"finger", fin0, 0, 0, NULLCHAR,
"ftp", ftp0, 0, 0, NULLCHAR,
#ifdef NETROM
"netrom", nr40, 0, 0, NULLCHAR,
#endif
"smtp", smtp0, 0, 0, NULLCHAR,
"telnet", tn0, 0, 0, NULLCHAR,
"remote", rem0, 0, 0, NULLCHAR,
NULLCHAR,
};
static int
dostart(argc,argv,p)
int argc;
char *argv[];
void *p;
{
return subcmd(Startcmds,argc,argv,p);
}
static int
dostop(argc,argv,p)
int argc;
char *argv[];
void *p;
{
return subcmd(Stopcmds,argc,argv,p);
}
#endif /* SERVERS */
/* Various configuration-dependent functions */
/* Process packets in the Hopper */
static void
network(i,v1,v2)
int i;
void *v1;
void *v2;
{
struct mbuf *bp;
struct phdr phdr;
char i_state;
loop: i_state = dirps();
while(Hopper == NULLBUF)
pwait(&Hopper);
restore(i_state);
/* Process the input packet */
bp = dequeue(&Hopper);
pullup(&bp,(char *)&phdr,sizeof(phdr));
dump(phdr.iface,IF_TRACE_IN,phdr.type,bp);
switch(phdr.type){
#ifdef KISS
case TYPE_KISS:
kiss_recv(phdr.iface,bp);
break;
#endif
#ifdef AX25
case TYPE_AX25:
ax_recv(phdr.iface,bp);
break;
#endif
case TYPE_ETHER:
eproc(phdr.iface,bp);
break;
case TYPE_IP:
ip_route(bp,0);
break;
case TYPE_APPLETALK:
default:
free_p(bp);
break;
}
goto loop;
}
/* Socket status display command */
static int
dosock(argc,argv,p)
int argc;
char *argv[];
void *p;
{
register struct usock *up;
int s;
if(argc < 2){
printf("S# Type PCB Owner\n");
for(s=0;s<Nusock;s++){
up = &Usock[s];
if(up->type == NOTUSED)
continue;
printf("%2d %-8s%-8lx %lx (%s)\n",
s,Socktypes[up->type],ptol(up->cb.p),
ptol(up->owner),up->owner->name);
}
return 0;
}
s = atoi(argv[1]);
if(s < 0 || s >= Nusock){
printf("Number out of range\n");
return 1;
}
up = &Usock[s];
printf("%s %lx\n",Socktypes[up->type],ptol(up->cb.p));
if(up->cb.p == NULL)
return 0;
switch(up->type){
case TYPE_TCP:
st_tcp(up->cb.tcb);
break;
case TYPE_UDP:
st_udp(up->cb.udp,0);
break;
#ifdef AX25
case TYPE_AX25I:
st_ax25(up->cb.ax25);
break;
#endif
#ifdef NETROM
case TYPE_NETROML4:
donrdump(up->cb.nr4);
break;
#endif
}
return 0;
}